<template>
  <j-modal
    :title="`主动退款处理`"
    :width="400"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-form-model :label-col="labelCol" :wrapper-col="wrapperCol">
<!--      <a-form-item label="退款审核">-->
<!--        <a-select v-model="model.status" placeholder="请选择">-->
<!--          <a-select-option value="1"> 审核通过 </a-select-option>-->
<!--          <a-select-option value="2"> 审核不通过 </a-select-option>-->
<!--        </a-select>-->
<!--      </a-form-item>-->

<!--      <a-form-item label="退款类型" v-if="model.status == '1'">-->
<!--        <a-select v-model="model.refundType" placeholder="请选择" @change="modelRefundType">-->
<!--          <a-select-option v-for="(item, index) in frefundType" :value="item.refundType" :key="index">-->
<!--            {{ refundType[item.refundType] }}-->
<!--          </a-select-option>-->
<!--          &lt;!&ndash; <a-select-option value="2"> 审核不通过 </a-select-option> &ndash;&gt;-->
<!--        </a-select>-->
<!--      </a-form-item>-->

      <a-form-item label="退款金额" >
        <a-input v-model="model.refundAmount" />
      </a-form-item>
    </a-form-model>
  </j-modal>
</template>

<script>
import moment from 'moment'
import { httpAction, getAction, orderRefundTypeList } from '@/api/manage'
export default {
  name: 'XhdjOrderInfoFinishRefund',
  data () {
    return {
      title: '操作',
      visible: false,
      model: { refundAmount: 0, refundType: '' },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },

      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/xhdjOrderInfo/xhdjOrderInfo/add',
        edit: '/xhdjOrderInfo/xhdjOrderInfo/edit',
        addFinishOrderRefund: '/order/xhdjAppCoachOrder/addFinishOrderRefund',
        orderRefundTypeList: '/xhdjOrderRefund/orderRefundTypeList'
      },
      outAmount: 0,
      frefundType: [],
      refundType: {
        0: '全额退款',
        1: '扣款车费',
        2: '扣款车费+空单费'
      }
    }
  },
  created () {},
  methods: {
    add () {
      //初始化默认值
      this.edit({})
    },
    edit (record) {
      this.model.id = record.id
      this.model.refundAmount = record.outAmount
      this.outAmount = record.outAmount
      this.visible = true

      var params = {
        orderId: record.id
      }
      orderRefundTypeList(this.url.orderRefundTypeList, params).then(res => {
        console.log(res)
        // this.frefundType = res.result
        // this.model.refundType = res.result[0].refundType
      })
    },
    close () {
      this.$emit('close')
      this.model = {
        id: null,
        refundAmount: null
      }
      this.outAmount = null
      this.visible = false
    },
    handleOk () {
      const that = this
      // 触发表单验证
      that.confirmLoading = true
      let httpurl = ''
      let method = ''
      httpurl += that.url.addFinishOrderRefund
      method = 'get'
      //                1                  268                   312
      // console.log(!that.model.status, this.outAmount < this.model.refundAmount, '输送机拉法基')
      // if (!that.model.status && this.outAmount < this.model.refundAmount) {
      //   that.confirmLoading = false
      //   return this.$message.error('请正确填写退款信息')
      // } else {
      //   that.confirmLoading = false
      // }
      getAction(httpurl, this.model, method).then(res => {
        if (res.success) {
          that.$message.success(res.message)
          that.$emit('ok')
          this.close()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleCancel () {
      this.close()
    },
    modelRefundType () {
      console.log('改变了', this.model.refundType)
      // this.model.refundAmount = this.frefundType[this.model.refundType].refundAmount
      this.frefundType.forEach(item => {
        if (item.refundType == this.model.refundType) {
          console.log(item.refundAmount)
          console.log(item.refundAmount, 'fladjflj ')
          this.model.refundAmount = item.refundAmount
        }
      })
    }
  }
}
</script>

<style lang="less" scoped></style>
